unit QQReader;

interface

uses
  SysUtils, Classes, Registry, Windows;

type
  TQQReader = class(TComponent)
  private
    fQQPath: string;
    fQQNumberList: TStringList;
    fQQNumbers: TStringList;
    fOnGetQQList: TNotifyEvent;
  protected
  public
    constructor Create(AOwner: TComponent); override;
    function GetQQList: TStringList;
  published
    property QQPath: string read fQQPath write fQQPath;
    property QQNumbers: TStringList read fQQNumbers write fQQNumbers;
    property OnGetQQList: TNotifyEvent read fOnGetQQList write fOnGetQQList;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Rarnu Components', [TQQReader]);
end;

{ TQQReader }

constructor TQQReader.Create(AOwner: TComponent);
var
  Reg: TRegistry;
begin
  inherited Create(AOwner);
  fQQNumbers := TStringList.Create;
  fQQNumbers.Clear;
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_LOCAL_MACHINE;
  if not Reg.KeyExists('SOFTWARE\TENCENT\QQ') then
  begin
    Reg.Free;
    fQQPath := '';
    Exit;
  end;
  Reg.OpenKey('SOFTWARE\TENCENT\QQ', false);
  fQQPath := Reg.ReadString('Install');
  Reg.CloseKey;
  Reg.Free;
  fQQNumbers := GetQQList;
end;

function TQQReader.GetQQList: TStringList;
var
  Sea: TSearchRec;
  i: Integer;
  QCode: Integer;
  Temp: TStringList;
begin
  Temp := TStringList.Create;
  Temp.Clear;
  fQQNumberList := TStringList.Create;
  fQQNumberList.Clear;
  if FindFirst(fQQPath + '*', faDirectory, Sea) = 0 then
  begin
    repeat
      if Sea.Attr = faDirectory then
        Temp.Add(Sea.Name);
    until FindNext(Sea) <> 0;
  end;
  for i := 0 to Temp.Count - 1 do
  begin
    try
      QCode := StrToInt(Temp.Strings[i]);
      if QCode <> 0 then
        fQQNumberList.Add(IntToStr(QCode));
    except
      Continue;
    end;
  end;
  Temp.Free;
  result := fQQNumberList;
  if Assigned(OnGetQQList) then
    OnGetQQList(self);
end;

end.

